#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <pthread.h>

int main(int argc, char const *argv[])
{
    pthread_mutex_t mutex;
    pthread_mutex_init(&mutex, NULL);

    pthread_mutex_lock(&mutex);

    if (pthread_mutex_trylock(&mutex) != 0)
    {
        printf("pthread_mutex_trylock: again!\n");
    }

    //绝对时间会受中途修改影响
    struct timespec tout;
    clock_gettime(CLOCK_REALTIME, &tout);
    tout.tv_sec += 10;
    if (pthread_mutex_timedlock(&mutex, &tout) != 0)
    {
        printf("pthread_mutex_timedlock: again!\n");
    }

    pthread_mutex_unlock(&mutex);

    pthread_mutex_destroy(&mutex);

    return 0;
}
